//
//  HWCommentViewController.m
//  嗨文
//
//  Created by 响当当 on 2019/1/17.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWCommentViewController.h"
#import "HWCommenCell.h"

@interface HWCommentViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;

@property (nonatomic, strong)NSArray *commentArr;//评论数据
@end

@implementation HWCommentViewController

- (NSArray *)commentArr
{
    if (!_commentArr)
    {
        _commentArr = [[NSArray alloc]init];
    }
    return _commentArr;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = 0;
        _tableView.backgroundColor = LCHexColor(0xF5F5F5);
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self buryPoint];
    [self setTitle:@"我的评论"];
    [self setDefaultNav];
    
    [self.view addSubview:self.tableView];
    
    [self getInfor];
}

#pragma mark - tableView delegate datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.commentArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWCommenCell *cell = [[HWCommenCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commenCell"];
    HWCommentModel *model = [[HWCommentModel alloc]initWithDic:self.commentArr[indexPath.row]];

    return [cell getBackRowHeight:model];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HWCommenCell *cell = [tableView dequeueReusableCellWithIdentifier:@"commenCell"];
    if (!cell)
    {
        cell = [[HWCommenCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"commenCell"];
        cell.selectionStyle = 0;
    }
    
    HWCommentModel *model = [[HWCommentModel alloc]initWithDic:self.commentArr[indexPath.row]];
    
    [cell getCommentDate:model];
    
    return cell;
}


#pragma mark - 获取评论数据
- (void)getInfor
{
    
    NSDictionary *prarmers = @{
                               @"access_token" : current_User.token,
                               @"pageNum" : @"1",
                               @"pageSize" : @"10"
                               };
    
    WeakSelf(self)
    [MyInfoManager getMyComment:prarmers sucess:^(id  _Nonnull acceptData) {
        DISMISS_SVP(1.0f);
        weakSelf.commentArr = [NSArray arrayWithArray:acceptData[@"list"]];
        [weakSelf.tableView reloadData];
       
    } fail:^(NSError * _Nullable error) {
        DISMISS_SVP(1.0f);
        [SVProgressHUD showErrorWithStatus:@"获取我的评论失败，请检查网络是否良好"];
        DISMISS_SVP(1.0f);
    }];
}

- (void)buryPoint
{
    NSString *lastStayTime = [kUserDefaults objectForKey:@"time"];
    NSString *nowStayTime = [NSString stringWithFormat:@"%ld",[[HWUtilties getNowTimeTimestamp3] integerValue] - lastStayTime.integerValue];
    
    [HWUtilties buryPointWithStayTime:nowStayTime
                            timestamp:[HWUtilties getNowTimeTimestamp3]
                             memberId:current_User.userID
                              fromUrl:nil
                                toUrl:@"/myComment"
                               fromId:nil
                                 toId:@"eecac1290a76d9e7"];
}

@end
